from django_celery_beat.models import PeriodicTask
from rest_framework.response import Response
from rest_framework.viewsets import ModelViewSet
from apps.CeleryTimedTask.serializers import *


class CeleryTimeTask(ModelViewSet):
    queryset = PeriodicTask.objects.all()
    serializer_class = TimedTaskSerializers
    ordering = ['id']

    def create(self, request, *args, **kwargs):
        res = super().create(request, *args, **kwargs)
        return Response({
            "code": 200,
            "data": {"data": res.data},
            "message": "OK",
        })

    def retrieve(self, request, *args, **kwargs):
        res = super().retrieve(request, *args, **kwargs)
        return Response({
            "code": 200,
            "data": {"data": res.data},
            "message": "OK",
        })

    def update(self, request, *args, **kwargs):
        res = super().update(request, *args, **kwargs)
        return Response({
            "code": 200,
            "data": {"data": res.data},
            "message": "OK",
        })